﻿using System;
using Itdavany.Data;
using Itdavany.Data.XmlFormat;
using Itdavany.Utility;
using RollingKitty.Data;

namespace RollingKitty.Objects.Converters
{
    public class AnimationConverter : DefaultConverter
    {
        public override ObjectType Type
        {
            get
            {
                return ObjectType.Animation;
            }
        }

        public override object Convert(ObjectDescription objDesc, ObjectDescriber objDescriber, WidgetFormat parentformat)
        {
            return Convert(objDesc, objDescriber);
        }

        public override object Convert(ObjectDescription objDesc, ObjectDescriber objDescriber)
        {
            AnimationClip.Animation animation = new AnimationClip.Animation();

            animation.Frames = (FrameArray)base.Convert(objDesc, objDescriber);
            animation.FrameTags = new System.Collections.Generic.List<AnimationClip.Animation.FrameTag>();

            foreach (Frame fdesc in objDesc.Frame)
            {
                AnimationClip.Animation.FrameTag frametag = new AnimationClip.Animation.FrameTag();
                frametag.delay = System.Convert.ToInt32(fdesc.Delay);

                animation.FrameTags.Add(frametag);
            }

            return animation;
        }
    }
}
